#include <sys_config.h>
#include <types.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>

#include <api/libosd/osd_lib.h>
#ifdef USB_MP_SUPPORT
#include <api/libfs2/statvfs.h>
//#include <api/libmp/media_player_api.h>
#include <api/libmp/lib_mp.h>
#endif

#ifdef DISK_MANAGER_SUPPORT
#include <api/libfs2/fs_main.h>
#include "disk_manager.h"
#endif

#include "osdobjs_def.h"
#include "string.id"
#include "images.id"
#include "osd_config.h"

#include "menus_root.h"
#include "win_com.h"
#include "win_com_popup.h"
#include "win_com_list.h"
#include "win_signalstatus.h"


#include "win_submenu.h"
#include "win_media.h"
#ifdef SUPPORT_VMX
#include <api/libcas/vmx/bc_consts.h>
#endif
#ifdef SUPPORT_VMX_STD	
#ifdef VMX_NEW_CC
#include <api/libcas/vmx/bc_consts.h>
#else
#include <api/libcas/vmx_std/bc_consts.h>
#endif
#endif
#if (defined(_S3281_)&&defined(_EROM_UPG_HOST_ENABLE_))
#include <api/libchunk/chunk.h>
#include <api/libupg/p2p_upgrade.h>
#endif

#if (_ALI_PLAY_VERSION_ >= 2)
#include "aliplay_service.h"
#endif

#if defined(SUPPORT_VMX_STD) || defined(SUPPORT_VMX)	// cover VMX_PATCH_PURSE
#if 0
#define VMX_API_PRINTF		libc_printf
#else
#define VMX_API_PRINTF(...)	do{}while(0)
#endif
#endif

#if defined( SUPPORT_CAS7) ||defined (SUPPORT_CAS9) 

	#if defined(SUPPORT_CAS9) 
		#include "conax_ap/conax_menu_handle.h"
		#include "conax_ap/win_ca_mmi.h"
	#endif
	#if defined( SUPPORT_CAS7) 
		#include "conax_ap7/win_ca_mmi.h"
	#endif
extern CONTAINER maturity_con;
extern CONTAINER win_ca_pin_con;  
extern CONTAINER win_ca_about_con;
extern CONTAINER win_subscription_con;
extern CONTAINER win_event_con;
extern CONTAINER win_purse_con;
extern CONTAINER win_debit_con;
extern CONTAINER win_credit_con;
extern CONTAINER g_win_mail;
extern CONTAINER g_win_mail_content;

static PRESULT ca_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);
static UINT8  ca_check_item_active(UINT32 id);

POBJECT_HEAD windows_ca_list[] =
{
    (POBJECT_HEAD)&win_subscription_con,
    (POBJECT_HEAD)&win_event_con,
    (POBJECT_HEAD)&win_purse_con,
    (POBJECT_HEAD)&win_ca_pin_con,
     (POBJECT_HEAD)&maturity_con,
     (POBJECT_HEAD)&win_ca_about_con,
    (POBJECT_HEAD)&g_win_mail,
};
#endif
static PRESULT mediaplayer_con_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);
static PRESULT editchannel_con_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);
static PRESULT installation_con_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);
static PRESULT system_con_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);
static PRESULT tools_con_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);
static PRESULT games_con_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

//Gavim@menu
static PRESULT root_time_con_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);


#ifndef DISABLE_PVR_TMS
static PRESULT record_con_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);
#endif

static UINT8  mediaplayer_check_item_active(UINT32 id);
static UINT8  editchannel_check_item_active(UINT32 id);
static UINT8  installation_check_item_active(UINT32 id);
static UINT8  system_check_item_active(UINT32 id);
static UINT8  tools_check_item_active(UINT32 id);
//Gavim@menu
static UINT8  root_time_check_item_active(UINT32 id);

#ifndef DISABLE_PVR_TMS
static UINT8  record_check_item_active(UINT32 id);
#endif

POBJECT_HEAD mediaplayer_sub_menus[] =
{
#ifndef DISABLE_USB
		#if(((!defined SUPPORT_CAS9)&&(!defined FTA_ONLY)&&(!defined SUPPORT_VMX_STD)&&(!defined SUPPORT_VMX))|| (defined MEDIAPLAYER_SUPPORT))
    	(POBJECT_HEAD)&g_win_usb_filelist,
    	(POBJECT_HEAD)&g_win_usb_filelist,
    	(POBJECT_HEAD)&g_win_usb_filelist,
    	(POBJECT_HEAD)&g_win_usb_filelist,

  	  #ifdef DLNA_DMP_SUPPORT
    	(POBJECT_HEAD)&g_win_usb_filelist,    	//DLNA DMP
      #endif
  	  #ifdef DLNA_DMR_SUPPORT
    	(POBJECT_HEAD)&g_win_dlna_dmr,    	//DLNA DMR
   	  #endif
      #ifdef DLNA_DMS_SUPPORT
    	(POBJECT_HEAD)&g_win_dms_setting,    	//DLNA DMS setting
      #endif

		#else
        //for 3281 32M no mediaplayer
        (POBJECT_HEAD)&g_win_usb_filelist,
        #endif
#endif
};

POBJECT_HEAD editchannel_sub_menus[] =
{
	(POBJECT_HEAD)&g_win_chanlist,
	(POBJECT_HEAD)&g_win_chanlist,
	NULL,
};

#if 1
POBJECT_HEAD  installation_sub_menus[] =
{
#ifdef DVBS_SUPPORT
      NULL,
#endif

#ifdef DVBT_SUPPORT
     NULL,   
#endif

#ifdef DVBC_SUPPORT
    NULL,
#endif

#ifdef DVBT_SUPPORT
    NULL,
#endif
};

#else

#if 1
POBJECT_HEAD  installation_sub_menus[] =
{
#if (SYS_PROJECT_FE == PROJECT_FE_DVBC)
	(POBJECT_HEAD)&g_win_quickscan,	/* like TP scan*/
	(POBJECT_HEAD)&win_country_net_con,
#else
	(POBJECT_HEAD)&g_win_antenna_connect,
	(POBJECT_HEAD)&g_win_satlist,
	(POBJECT_HEAD)&g_win_antenna_set_fixed,
	(POBJECT_HEAD)&g_win_sat_srchset,	/* Single search */
	(POBJECT_HEAD)&g_win_sat_srchset,	/* Multi search */
	(POBJECT_HEAD)&g_win_tplist,
#endif

    (POBJECT_HEAD)&g_win_channelscan,
    (POBJECT_HEAD)&g_win_autoscan,


#ifdef USB_LOGO_TEST
    	(POBJECT_HEAD)&g_win_usb_logo,
#endif
};

#else

#define MAX_INSTALLATION_ITEM   10
POBJECT_HEAD  installation_sub_menus[MAX_INSTALLATION_ITEM]; 

#endif

#endif

//gavim@menu
POBJECT_HEAD  root_time_sub_menus[] =
{
	(POBJECT_HEAD)&win_time_con,	
};
//----------------------

POBJECT_HEAD  system_sub_menus[] =
{
    // system
    //Gavim@menu remove
	//(POBJECT_HEAD)&win_lan_con,
	(POBJECT_HEAD)&win_av_con,
#if (AOV_OSD_DISPLAY_SETTING_ENABLE == SYS_FUNC_ON)
#ifdef DISPLAY_SETTING_SUPPORT
	(POBJECT_HEAD)&g_win_display_set,
#endif
#endif	
	//Gavim@menu remove
	//(POBJECT_HEAD)&win_time_con,
	(POBJECT_HEAD)&g_win_timerlist,
#ifdef SUPPORT_CAS_A
	(POBJECT_HEAD)&g_win_tv_access,
#endif
	(POBJECT_HEAD)&win_parental_con,
	(POBJECT_HEAD)&win_osdset_con,

#ifdef _INVW_JUICE
#else
#ifdef FAV_GROP_RENAME	
	(POBJECT_HEAD)&g_win_favgrplst,
#endif
#endif
#ifdef AUDIO_DESCRIPTION_SUPPORT
	(POBJECT_HEAD)&g_win_aud_desc,
#endif
#ifdef MULTIVIEW_SUPPORT
    (POBJECT_HEAD)&g_win_multiviewset,
#endif

#ifndef DISABLE_PVR_TMS
        (POBJECT_HEAD)&g_win_disk_info,
	(POBJECT_HEAD)&g_win_pvr_setting,	
#endif

#ifdef _INVW_JUICE
#ifndef DISK_MANAGER_SUPPORT
    // PVR Manage
    // HDD Format
#endif
#endif
	(POBJECT_HEAD)&g_win_misc_setting,

};

POBJECT_HEAD tools_sub_menus[] =
{
    // tools
	(POBJECT_HEAD)&win_info_con,
	(POBJECT_HEAD)&win_factoryset_con,
#if (AOV_OSD_GAME_ENABLE == SYS_FUNC_ON)
	(POBJECT_HEAD)&game_con,
	(POBJECT_HEAD)&game_sudoku_con,
#endif

#if (AOV_OSD_UPGRADE_USE_RS232_ENABLE == SYS_FUNC_ON)
//#if((defined _S3281_)||(!(defined(SUPPORT_CAS7) ||defined(SUPPORT_CAS9))))
#if((defined(_S3281_)&&defined(_EROM_UPG_HOST_ENABLE_))	||(!(defined(SUPPORT_CAS9)||defined(FTA_ONLY)||defined(CI_PLUS_SUPPORT) || defined(SUPPORT_VMX)||defined(SUPPORT_VMX_STD))))	
	(POBJECT_HEAD)&win_rs232upg_con,
#endif	
#endif

#ifdef _INVW_JUICE
#else
	(POBJECT_HEAD)&win_ota_combo,
#endif
#ifdef CI_SUPPORT
	(POBJECT_HEAD)&g_win_ci_slots,
#endif
//	(POBJECT_HEAD)&win_satcodx_con,
#ifdef USB_MP_SUPPORT
	#ifndef DISABLE_USB_UPG//ndef SUPPORT_CAS9
	(POBJECT_HEAD)&win_usbupg_con,
	#endif

	#ifndef DISABLE_USB
    	#ifdef USB_SAFELY_REMOVE_SUPPORT
  	(POBJECT_HEAD)&g_win_usb_filelist,
    	#endif
	#endif
#endif

#ifdef NETWORK_SUPPORT
//#ifdef WIFI_SUPPORT	
//#ifdef _INVW_JUICE
//#else
//#ifdef WIFI_DIRECT_SUPPORT 
//	(POBJECT_HEAD)&g_win_wifi_direct_setting,
//#endif
//#endif
//#endif	
	(POBJECT_HEAD)&g_win_netupg,
#ifdef SAT2IP_CLIENT_SUPPORT//SAT2IP_SUPPORT
	(POBJECT_HEAD)&g_win_satip_client,
#endif

#ifdef SAT2IP_SERVER_SUPPORT//SAT2IP_SUPPORT

#ifdef SAT2IP_FIX_TUNER
	(POBJECT_HEAD)&g_win_satip_serv_install,
#endif
    (POBJECT_HEAD)&g_win_satip_serv_setting,
#ifdef PVR2IP_SERVER_SUPPORT
    (POBJECT_HEAD)&g_win_pvrip_serv_setting,
#endif

#endif
#endif

#ifdef HDMI_CERTIFICATION_UI      
	(POBJECT_HEAD)&win_hdmi_certify_con,
#endif
//modify bomur 2011 09 17
#ifdef MAC_TEST
	(POBJECT_HEAD)&g_win_mac_submenu,
	(POBJECT_HEAD)&test_win_mainmenu,
#endif
#ifdef USB_LOGO_TEST
    	(POBJECT_HEAD)&g_win_usb_logo,
#endif
//modify end
	#ifdef SUPPORT_IRAN_CALENDAR
	(POBJECT_HEAD)&win_calender_con,
#endif

#ifdef SUPPORT_CAS_A
	(POBJECT_HEAD)&g_win_mail,
#endif

#if (_ALI_PLAY_VERSION_ >= 2)
	(POBJECT_HEAD)&win_aliplay_pairing_con,
#endif
#ifdef ALICAST_SUPPORT
	(POBJECT_HEAD)&g_win_alicast,
#endif
#ifdef NETWORK_SUPPORT
	(POBJECT_HEAD)&g_win_net_choose,
#endif
};

POBJECT_HEAD games_sub_menus[] =
{
    // game
	//(POBJECT_HEAD)&game_con,
	(POBJECT_HEAD)&game_con,
	(POBJECT_HEAD)&game_sudoku_con,
};

POBJECT_HEAD record_sub_menus[] =
{
	(POBJECT_HEAD)&g_win_disk_info,
	(POBJECT_HEAD)&g_win_pvr_setting,
};

sub_menu_item_t mediaplayer_items[] = 
{
#ifndef DISABLE_USB
    	#if(((!defined SUPPORT_CAS9)&&(!defined FTA_ONLY)&&(!defined SUPPORT_VMX_STD)&&(!defined SUPPORT_VMX))|| (defined MEDIAPLAYER_SUPPORT))
//Gavim@20141231_menu string 
   	{ITEM_TYPE_NOMAL,       RS_PVR_MAIN_MENU,  0,	mediaplayer_con_item_callback},
    	{ITEM_TYPE_NOMAL,	RS_MP_VIDEO,		       0,	mediaplayer_con_item_callback},
    	{ITEM_TYPE_NOMAL,	RS_MP_MUSIC,		       0,	mediaplayer_con_item_callback},
    	{ITEM_TYPE_NOMAL,	RS_MP_IMAGE,		       0,	mediaplayer_con_item_callback},
  	  #ifdef DLNA_DMP_SUPPORT
    	{ITEM_TYPE_NOMAL,	RS_DLNA_DMP,		       0,	mediaplayer_con_item_callback},
   	  #endif
  	  #ifdef DLNA_DMR_SUPPORT
    	{ITEM_TYPE_NOMAL,	RS_SMALL_2_BIG,		       0,	mediaplayer_con_item_callback},
   	  #endif
  	  #ifdef DLNA_DMS_SUPPORT
    	{ITEM_TYPE_NOMAL,	RS_DLNA_DMS_SETTING,	   0,	mediaplayer_con_item_callback},
      #endif
        #else
        //for 3281 32M no mediaplayer
        {ITEM_TYPE_NOMAL,	RS_RECORD_MANAGER,  0,	mediaplayer_con_item_callback},
        #endif
#endif	
};

sub_menu_item_t editchannel_items[] = 
{
	{ITEM_TYPE_NOMAL,	RS_CHANNEL_TV_CHANNEL_LIST,		0,	editchannel_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_CHANNEL_RADIO_CHANNEL_LIST,	0,	editchannel_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_DELETE_ALL,					0,	editchannel_con_item_callback},
};

//Gavim@menu
sub_menu_item_t root_time_items[] =
{
	{ITEM_TYPE_NOMAL,	RS_SYSTEM_TIMER_SETTING,0,	root_time_con_item_callback},	
//	{ITEM_TYPE_NOMAL,	RS_CHANNEL_RADIO_CHANNEL_LIST,	0,	editchannel_con_item_callback},
};


#if 0
sub_menu_item_t installation_items[] = 
{
#if (SYS_PROJECT_FE == PROJECT_FE_DVBC)
	{ITEM_TYPE_NOMAL,	RS_INSTALLATION_QUICK_SEARCH,	0,	installation_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_INSTALLATION_AUTO_SEARCH,	0,	installation_con_item_callback},
#else
    // installation
	{ITEM_TYPE_NOMAL,	RS_ANTENNA_CONECTION,			0,	installation_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_SATELLITE_LIST,				0,	installation_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_INSTALLATION_ANTENNA_SETUP,	0,	installation_con_item_callback},	
	{ITEM_TYPE_NOMAL,	RS_INSTALLATION_SINGLE_SEARCH,	0,	installation_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_INSTALLATION_MULTI_SEARCH,	0,	installation_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_TP_LIST,						0,	installation_con_item_callback},
#endif

    {ITEM_TYPE_NOMAL,   RS_ISDBT_CHAN_SCAN,             0,  installation_con_item_callback},
    {ITEM_TYPE_NOMAL,   RS_ISDBT_AUTO_SCAN,             0,  installation_con_item_callback},


#ifdef USB_LOGO_TEST
	//{ITEM_TYPE_NOMAL,	RS_USB_LOGO_TEST,	    			0,	tools_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_USB_LOGO_TEST,	    			0,	installation_con_item_callback},
#endif
};
#else

sub_menu_item_t installation_items[] =
{
#ifdef DVBS_SUPPORT
	{ITEM_TYPE_NOMAL,	RS_INSTALLATION_DVBS,	0,	installation_con_item_callback},
#endif

#ifdef DVBT_SUPPORT
	{ITEM_TYPE_NOMAL,	RS_INSTALLATION_DVBT,	0,	installation_con_item_callback},
#endif

#ifdef DVBC_SUPPORT
	{ITEM_TYPE_NOMAL,	RS_INSTALLATION_DVBC,	0,	installation_con_item_callback},
#endif

#ifdef ISDBT_SUPPORT
	{ITEM_TYPE_NOMAL,	RS_INSTALLATION_ISDBT,	0,	installation_con_item_callback},
#endif
};

#endif

#if defined( SUPPORT_CAS7) ||defined (SUPPORT_CAS9) 
sub_menu_item_t ca_access_items[] = 
{
	{ITEM_TYPE_NOMAL,	RS_CONAX_SUBSCRIPTION_STATUS,	0,	ca_item_callback},
	{ITEM_TYPE_NOMAL,	RS_CONAX_EVENT_STATUS,			0,	ca_item_callback},
	{ITEM_TYPE_NOMAL,	RS_CONAX_TOKEN_STATUS,	        0,	ca_item_callback},	
	{ITEM_TYPE_NOMAL,	RS_CONAX_CA_PIN,	            0,	ca_item_callback},
	{ITEM_TYPE_NOMAL,	RS_CONAX_MATURITY_RATING,	    0,	ca_item_callback},
	{ITEM_TYPE_NOMAL,	RS_CONAX_ABOUT,					0,	ca_item_callback},
    {ITEM_TYPE_NOMAL,	RS_CA_INDEX_MAIL_LIST,			0,	ca_item_callback},
};
#endif
#if defined(SUPPORT_VMX_STD) || defined(SUPPORT_VMX)
extern CONTAINER win_purse_con_vmx;
extern CONTAINER win_ca_pin_con_vmx;
extern CONTAINER win_ca_about_con_vmx;
//extern CONTAINER win_pin_type;
POBJECT_HEAD windows_vmx_ca_list[] =
{
	(POBJECT_HEAD)&win_purse_con_vmx,
	(POBJECT_HEAD)&win_ca_about_con_vmx,
	//(POBJECT_HEAD)&win_pin_type//win_ca_pin_con_vmx
};

INT8 get_check_nsc_result() {
	INT8 check_nsc_ret = 0;
	check_nsc_ret = BC_CheckNSc();
	//libc_printf("check_nsc_ret=%d\n", check_nsc_ret);
	return check_nsc_ret;
}

BOOL is_vmx_ca_menu_active = FALSE;
UINT8  vmx_ca_check_item_active(UINT32 id)
{
	//libc_printf("vmx_ca_check_item_active=%d\n", is_vmx_ca_menu_active);
	UINT8 action;
	switch(id)
	{
	case WIN_TOKENS_STATUS:
	case WIN_CA_ABOUT:
	//case WIN_PIN_TYPE:
#if 0
		if (get_check_nsc_result() == k_BcSuccess|| is_vmx_ca_menu_active == TRUE) {
			action = C_ATTR_ACTIVE;			
		} else {
			action = C_ATTR_INACTIVE;		
		}
#else
		action = C_ATTR_ACTIVE;
#endif
		break;
	}

	return action;
}

extern void purse_function(uint8_t bNumber,uint32_t* lPurse,uint16_t wMult,uint16_t wDiv,uint8_t bLocation,
	uint8_t bSign0,uint8_t bSign1000,uint8_t bCount,uint8_t bLen,uint8_t *abText);
extern BOOL get_puese_callback();
extern sub_menu_t* sub_menu_desc;

#if defined(VMX_PATCH_PURSE)
#define MAX_PURSE	8	
extern UINT8 vmx_purse_tmp_buf[MAX_PURSE][100];
extern UINT8 vmx_purse_name_buf[MAX_PURSE][100];
extern UINT8 purse_entries_num;
extern BOOL is_get_puese_callback;
#else
extern UINT8 vmx_purse_tmp_buf[1][100];
#endif

static PRESULT vmx_ca_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);
static void enter_sub_menu(POBJECT_HEAD* menus, UINT32 idx);
sub_menu_item_t vmx_ca_items[] = 
{
	{ITEM_TYPE_NOMAL,	RS_VMX_TOKEN_STATUS,	0,	vmx_ca_item_callback},	
	{ITEM_TYPE_NOMAL,	RS_VMX_ABOUT,			0,	vmx_ca_item_callback},		
	//{ITEM_TYPE_NOMAL,	RS_VMX_CHANGE_CA_PIN,			0,	vmx_ca_item_callback}
};
sub_menu_t sub_menu_vmx_ca =
{
    ARRAY_SIZE(vmx_ca_items),
    RS_VMX_CONDITIONAL_ACCESS,
    vmx_ca_items,
    NULL,
    vmx_ca_check_item_active,
    C_SUBMENU_PAGE,0,0,
};
static PRESULT vmx_ca_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2) 
{

	PRESULT ret = PROC_PASS;
	UINT8	unact;
       UINT8 back_saved;
	UINT8	id = OSD_GetObjID(pObj) + sub_menu_desc->list_top;
       struct smc_device *smc_dev;
	smc_dev = (struct smc_device *)dev_get_by_id(HLD_DEV_TYPE_SMC, 0);

	#if defined(VMX_PATCH_PURSE)
	#define WAIT_TIME_SEC	15
	#endif
	
	switch(event)
	{
	case EVN_UNKNOWN_ACTION:
		if (id == 1) {
			MEMSET(vmx_purse_tmp_buf, 0, sizeof(vmx_purse_tmp_buf));
			
			#if defined(VMX_PATCH_PURSE)
			MEMSET(vmx_purse_name_buf, 0, sizeof(vmx_purse_name_buf));
			purse_entries_num=0;
			is_get_puese_callback=FALSE;
			VMX_API_PRINTF("%s call BC_GetPurse\n",__FUNCTION__);
			#endif

			#ifdef SUPPORT_VMX
			vmx_cas_bc_lock();
			BC_GetPurse(purse_function);
			vmx_cas_bc_unlock();
			#else
			BC_GetPurse(purse_function);
			#endif

			UINT8 i = 0;
			
            #if defined(VMX_PATCH_PURSE)
			while (get_puese_callback() == FALSE && i <= WAIT_TIME_SEC) { 
            #else
			while (get_puese_callback() == FALSE && i <= 15) { // waiting at most 1500 ms
            #endif				
				osal_task_sleep(100);
				i++;
			}
			
		} 
		enter_sub_menu(windows_vmx_ca_list,id - 1);
		
              ret = PROC_LOOP;
		break;
	}

	return ret;
}

#endif

sub_menu_item_t system_items[] = 
{
    // system

// Gavim@menu    

	// Gavim@menu remove
	//{ITEM_TYPE_NOMAL,	RS_SYSTEM_LANGUAGE,		0,	system_con_item_callback},

	{ITEM_TYPE_NOMAL,	RS_SYSTEM_TV_SYSTEM,	0,	system_con_item_callback},
#if (AOV_OSD_DISPLAY_SETTING_ENABLE == SYS_FUNC_ON)
#ifdef DISPLAY_SETTING_SUPPORT
	{ITEM_TYPE_NOMAL,	RS_SYSTEM_DISPLAY_SET,	0,	system_con_item_callback},
#endif
#endif		

	// Gavim@menu remove
	//{ITEM_TYPE_NOMAL,	RS_SYS_LOCAL_TIMER_SET,	0,	system_con_item_callback},


	{ITEM_TYPE_NOMAL,	RS_SYSTEM_TIMER_SETTING,0,	system_con_item_callback},

#ifdef SUPPORT_CAS_A   
	{ITEM_TYPE_NOMAL,	RS_ABEL_TV_ACCESS,		0,	system_con_item_callback},
#endif
	{ITEM_TYPE_NOMAL,	RS_SYSTME_PARENTAL_LOCK,0,	system_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_SYSTEM_OSD_SETTING,	0,	system_con_item_callback},

#ifdef _INVW_JUICE
#else
#ifdef FAV_GROP_RENAME
	{ITEM_TYPE_NOMAL,	RS_FAVORITE,			0,	system_con_item_callback},
#endif
#endif
#ifdef AUDIO_DESCRIPTION_SUPPORT
	{ITEM_TYPE_NOMAL,	RS_AUDIO_DESCRIPTION_SETTING, 0, system_con_item_callback},
#endif
#ifdef MULTIVIEW_SUPPORT
	{ITEM_TYPE_NOMAL,	RS_MULTIVIEW_SETTING,	0,	system_con_item_callback},
#endif

#ifndef DISABLE_PVR_TMS
        {ITEM_TYPE_NOMAL,	RS_HDD_NFORMATION,		0,	system_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_PVR_SETTING, 		       0,	system_con_item_callback},
#endif

	{ITEM_TYPE_NOMAL,	RS_OTHER,				0,	system_con_item_callback},

};

sub_menu_item_t tools_items[] = 
{
    // tools
	{ITEM_TYPE_NOMAL,	RS_TOOLS_INFORMATION,		0,	tools_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_TOOLS_FACTORY_SETTING,	0,	tools_con_item_callback},
#if (AOV_OSD_GAME_ENABLE == SYS_FUNC_ON)
	{ITEM_TYPE_NOMAL,	RS_GAME_OTHELLO,	0,	tools_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_GAME_SUDOKU,		0,	tools_con_item_callback},
#endif

#if (AOV_OSD_UPGRADE_USE_RS232_ENABLE == SYS_FUNC_ON)
//#if((defined _S3281_)||(!(defined(SUPPORT_CAS7) ||defined(SUPPORT_CAS9))))
#if((defined(_S3281_)&&defined(_EROM_UPG_HOST_ENABLE_))	||(!(defined(SUPPORT_CAS9)||defined(FTA_ONLY)||defined(CI_PLUS_SUPPORT)||defined(SUPPORT_VMX)||defined(SUPPORT_VMX_STD) )))
	{ITEM_TYPE_NOMAL,	RS_UPGRADE_MODE_RS232,		0,	tools_con_item_callback},
#endif	
#endif

#ifdef _INVW_JUICE
#else
	{ITEM_TYPE_NOMAL,	RS_TOOLS_SW_UPGRADE_BY_OTA,	0,	tools_con_item_callback},
#endif
#ifdef CI_SUPPORT		
	{ITEM_TYPE_NOMAL,	RS_CI,						0,	tools_con_item_callback},		
#endif		
//	{ITEM_TYPE_NOMAL,	RS_TOOLS_UPGRADE_SATCODX,	0,	tools_con_item_callback},
#ifdef USB_MP_SUPPORT
	#ifndef DISABLE_USB_UPG//ndef SUPPORT_CAS9
	{ITEM_TYPE_NOMAL,	RS_USBUPG_UPGRADE_BY_USB,	0,	tools_con_item_callback},	
	#endif

	#ifndef DISABLE_USB
    	//#if(defined (MEDIAPLAYER_SUPPORT) || !(defined( SUPPORT_CAS9) ||defined (SUPPORT_CAS7) ))
    	#ifdef USB_SAFELY_REMOVE_SUPPORT
    	{ITEM_TYPE_NOMAL,	RS_USB_SAFELY_REMOVE,	    0,	tools_con_item_callback},
    	#endif
	#endif
#endif

#ifdef NETWORK_SUPPORT
//#ifdef WIFI_SUPPORT		
//#ifdef _INVW_JUICE
//#else
//#ifdef WIFI_DIRECT_SUPPORT
//	{ITEM_TYPE_NOMAL,	RS_WIFI_DIRECT,		        0,	tools_con_item_callback},
//#endif
//#endif	
//#endif	
	{ITEM_TYPE_NOMAL,	RS_NET_UPGRADE,		        0,	tools_con_item_callback},
#ifdef SAT2IP_CLIENT_SUPPORT//SAT2IP_SUPPORT
	{ITEM_TYPE_NOMAL,	RS_SATIP_CLIENT,			0, 	tools_con_item_callback},
#endif // SAT2IP_SUPPORT
#ifdef SAT2IP_SERVER_SUPPORT//SAT2IP_SUPPORT
#ifdef SAT2IP_FIX_TUNER
	{ITEM_TYPE_NOMAL,	RS_SATIP_SERVER_INSTALLATION,			0, 	tools_con_item_callback},
#endif
	{ITEM_TYPE_NOMAL,	RS_SATIP_SERVER_SETTING,			0, 	tools_con_item_callback},
#endif 
#ifdef PVR2IP_SERVER_SUPPORT
    {ITEM_TYPE_NOMAL,	RS_PVR2IP_SERVER_SETTING,			0, 	tools_con_item_callback},
#endif
#endif
#ifdef HDMI_CERTIFICATION_UI      
	{ITEM_TYPE_NOMAL,		RS_HDMI_CERT,		0,	tools_con_item_callback}, 
#endif
//modify bomur 2011 09 17
#ifdef MAC_TEST
	{ITEM_TYPE_NOMAL,	RS_TOOLS_MAC_TEST,			0,	tools_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_IOL_MAC_TEST,		0,	tools_con_item_callback},
#endif
#ifdef USB_LOGO_TEST
	//{ITEM_TYPE_NOMAL,	RS_USB_LOGO_TEST,	    			0,	tools_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_USB_LOGO_TEST,	    			0,	tools_con_item_callback},
#endif
//modify end

	#ifdef SUPPORT_IRAN_CALENDAR
	{ITEM_TYPE_NOMAL,	RS_CALENDAR,		0,	tools_con_item_callback},
#endif


#ifdef SUPPORT_CAS_A	
	{ITEM_TYPE_NOMAL,	RS_ABEL_MAILBOX,		0,	tools_con_item_callback},
#endif
#ifdef _ALI_PLAY_VERSION_
	{ITEM_TYPE_NOMAL,	RS_ALIPLAY_PAIR,		0,	tools_con_item_callback},
#endif
#ifdef ALICAST_SUPPORT
	{ITEM_TYPE_NOMAL,	RS_ALICAST,			0, 	tools_con_item_callback},
#endif
#ifdef NETWORK_SUPPORT
	{ITEM_TYPE_NOMAL,	RS_NETWORK_SETTING,			0, 	tools_con_item_callback},
#endif
};

sub_menu_item_t games_items[] = 
{
    // game
	{ITEM_TYPE_NOMAL,	RS_GAME_OTHELLO,	0,	games_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_GAME_SUDOKU,		0,	games_con_item_callback},

};

#ifndef DISABLE_PVR_TMS
#ifdef DVR_PVR_SUPPORT
#ifndef DISABLE_USB
sub_menu_item_t record_items[] = 
{
	{ITEM_TYPE_NOMAL,	RS_HDD_NFORMATION,		0,	record_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_PVR_SETTING, 		0,	record_con_item_callback},
};
#endif
#endif
#endif

sub_menu_t sub_menu_mediaplayer = 
{
	ARRAY_SIZE(mediaplayer_items),
#if(((!defined SUPPORT_CAS9)&&(!defined FTA_ONLY)&&(!defined SUPPORT_VMX_STD)&&(!defined SUPPORT_VMX))|| (defined MEDIAPLAYER_SUPPORT))
    RS_COMMON_MEDIA_PLAYER,
#else
	RS_RECORD_MANAGER,
#endif	
	mediaplayer_items,
	NULL,
	mediaplayer_check_item_active,
	C_SUBMENU_PAGE,	0, 0,
};

sub_menu_t sub_menu_editchannel = 
{
	ARRAY_SIZE(editchannel_items),
#if Maker_GUI_ON
	RS_CHANNEL,
#else
	RS_MENU_PROGRAM,		
#endif	
	editchannel_items,
	NULL,
	editchannel_check_item_active,
	C_SUBMENU_PAGE,	0, 0,
};

#if 1
sub_menu_t sub_menu_installation = 
{
	ARRAY_SIZE(installation_items),
	RS_INSTALLATION,		
	installation_items,		
	NULL,
	installation_check_item_active,
	C_SUBMENU_PAGE,	0, 0,
};
#else

sub_menu_t sub_menu_installation;

#endif

#if defined( SUPPORT_CAS7) ||defined (SUPPORT_CAS9) 
sub_menu_t sub_menu_conditional_access =
{
    ARRAY_SIZE(ca_access_items),
    RS_CONAX_CA,
    ca_access_items,
    NULL,
    ca_check_item_active,
    C_SUBMENU_PAGE,0,0,
};
#endif

sub_menu_t sub_menu_system = 
{
	ARRAY_SIZE(system_items),
	RS_SYSTEM_SETUP,		
	system_items,
	NULL,
	system_check_item_active,
	C_SUBMENU_PAGE,	0, 0,
};

sub_menu_t sub_menu_tools = 
{
	ARRAY_SIZE(tools_items),
	RS_TOOLS,		
	tools_items,		
	NULL,
	tools_check_item_active,
	C_SUBMENU_PAGE,	0, 0,
};
//Gavim@YJ
//Gavim@menu

sub_menu_t sub_menu_time = 
{
	ARRAY_SIZE(root_time_items),
	RS_TOOLS,		
	root_time_items,		
	NULL,
	root_time_check_item_active,
	C_SUBMENU_PAGE,	0, 0,
};
sub_menu_t sub_menu_language = 
{
	ARRAY_SIZE(tools_items),
	RS_TOOLS,		
	tools_items,		
	NULL,
	tools_check_item_active,
	C_SUBMENU_PAGE,	0, 0,
};

sub_menu_t sub_menu_games = 
{
	ARRAY_SIZE(games_items),
	RS_GAME,		
	games_items,		
	NULL,
	NULL,
	C_SUBMENU_PAGE,	0, 0,
};


#ifndef DISABLE_PVR_TMS
#ifdef DVR_PVR_SUPPORT
#ifndef DISABLE_USB
sub_menu_t sub_menu_record = 
{
	ARRAY_SIZE(record_items),
	RS_DVR_REC,
	record_items,
	NULL,
	record_check_item_active,
	C_SUBMENU_PAGE,	0, 0,
};
#endif
#endif
#endif

static POBJECT_HEAD  dvbs_installation_submenu_items[] =
{
#ifdef DVBS_SUPPORT
	(POBJECT_HEAD)&g_win_antenna_connect,
	(POBJECT_HEAD)&g_win_satlist,
	(POBJECT_HEAD)&g_win_antenna_set_fixed,
	(POBJECT_HEAD)&g_win_sat_srchset,	/* Single search */
	(POBJECT_HEAD)&g_win_sat_srchset,	/* Multi search */
	(POBJECT_HEAD)&g_win_tplist,
#endif
};

static POBJECT_HEAD  dvbt_installation_submenu_items[] =
{
#ifdef DVBT_SUPPORT    
    (POBJECT_HEAD)&g_win_channelscan,
    (POBJECT_HEAD)&g_win_autoscan,
#if (AOV_OSD_LCN_ENABLE == SYS_FUNC_ON)
#ifdef _LCN_ENABLE_
//#ifndef DVBS_SUPPORT
    (POBJECT_HEAD)&g_win_LCN,
// #endif
#endif
#endif
#endif
};

static POBJECT_HEAD  isdbt_installation_submenu_items[] =
{
#ifdef ISDBT_SUPPORT    
    (POBJECT_HEAD)&g_win_channelscan,
    (POBJECT_HEAD)&g_win_autoscan,
#if (AOV_OSD_LCN_ENABLE == SYS_FUNC_ON)
#ifdef _LCN_ENABLE_
//#ifndef DVBS_SUPPORT
    (POBJECT_HEAD)&g_win_LCN,
 //#endif
#endif
#endif
#endif
};

static POBJECT_HEAD  dvbc_installation_submenu_items[] =
{
#ifdef DVBC_SUPPORT
    (POBJECT_HEAD)&g_win_quickscan, /* like TP scan*/
    (POBJECT_HEAD)&win_country_net_con,
#endif
};

static sub_menu_item_t dvbs_installation_items[] = 
{
	{ITEM_TYPE_NOMAL,	RS_ANTENNA_CONECTION,			0,	installation_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_SATELLITE_LIST,				0,	installation_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_INSTALLATION_ANTENNA_SETUP,	0,	installation_con_item_callback},	
	{ITEM_TYPE_NOMAL,	RS_INSTALLATION_SINGLE_SEARCH,	0,	installation_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_INSTALLATION_MULTI_SEARCH,	0,	installation_con_item_callback},
	{ITEM_TYPE_NOMAL,	RS_TP_LIST,						0,	installation_con_item_callback},
};

static sub_menu_item_t isdbt_installation_items[] = 
{
    {ITEM_TYPE_NOMAL,   RS_ISDBT_CHAN_SCAN,             0,  installation_con_item_callback},
    {ITEM_TYPE_NOMAL,   RS_ISDBT_AUTO_SCAN,             0,  installation_con_item_callback},
#if (AOV_OSD_LCN_ENABLE == SYS_FUNC_ON)
#ifdef _LCN_ENABLE_
//#ifndef DVBS_SUPPORT
    {ITEM_TYPE_NOMAL,   RS_INSTALLATION_VCN,            0,  installation_con_item_callback},
 //#endif
#endif  
#endif
};

static sub_menu_item_t dvbt_installation_items[] = 
{
    {ITEM_TYPE_NOMAL,   RS_DVBT_CHAN_SCAN,             0,  installation_con_item_callback},
    {ITEM_TYPE_NOMAL,   RS_DVBT_AUTO_SCAN,             0,  installation_con_item_callback},
#if (AOV_OSD_LCN_ENABLE == SYS_FUNC_ON)
#ifdef _LCN_ENABLE_
//#ifndef DVBS_SUPPORT
    {ITEM_TYPE_NOMAL,   RS_INSTALLATION_LCN,            0,  installation_con_item_callback},
 //#endif
#endif        
#endif
};


static sub_menu_item_t dvbc_installation_items[] = 
{	
    {ITEM_TYPE_NOMAL,	RS_INSTALLATION_QUICK_SEARCH,	0,	installation_con_item_callback},
    {ITEM_TYPE_NOMAL,	RS_INSTALLATION_AUTO_SEARCH,	0,	installation_con_item_callback},
};


sub_menu_t sub_menu_installation_dvbs = 
{
	ARRAY_SIZE(dvbs_installation_items),
	RS_INSTALLATION_DVBS,		
	dvbs_installation_items,		
	NULL,
	installation_check_item_active,
	C_SUBMENU_PAGE,	0, 0,    
};




sub_menu_t sub_menu_installation_dvbt = 
{
	ARRAY_SIZE(dvbt_installation_items),
	RS_INSTALLATION_DVBT,		
	dvbt_installation_items,		
	NULL,
	installation_check_item_active,
	C_SUBMENU_PAGE,	0, 0,
    
};

sub_menu_t sub_menu_installation_dvbc = 
{

	ARRAY_SIZE(dvbc_installation_items),
	RS_INSTALLATION_DVBC,		
	dvbc_installation_items,		
	NULL,
	installation_check_item_active,
	C_SUBMENU_PAGE,	0, 0,

    
};

sub_menu_t sub_menu_installation_isdbt = 
{

	ARRAY_SIZE(isdbt_installation_items),
	RS_INSTALLATION_ISDBT,		
	isdbt_installation_items,		
	NULL,
	installation_check_item_active,
	C_SUBMENU_PAGE,	0, 0,    
};

//////////////////////////////////////////////////////////////////////////////
// sub menu structure definition
//////////////////////////////////////////////////////////////////////////////
/*
sub_menu_t* mainmenu_sub_menus[] = 
{

	&sub_menu_mediaplayer,
	&sub_menu_editchannel,
	&sub_menu_installation_dvbt,
	&sub_menu_system,
	&sub_menu_tools,
	&sub_menu_time,
	&sub_menu_language,
};
*/
//Gavim@menu
sub_menu_t* mainmenu_sub_menus[] = 
{
	&sub_menu_mediaplayer,
	&sub_menu_editchannel,
	&sub_menu_time,
	&sub_menu_installation_dvbt,
	&sub_menu_language,
	&sub_menu_system,
	&sub_menu_tools,
};

static UINT8 isdbt_pos_min = 0xff;
static UINT8 isdbt_pos_max = 0xff;
extern sub_menu_t* sub_menu_desc;
extern BOOL from_auto_scan;
static void enter_sub_menu(POBJECT_HEAD* menus, UINT32 idx)
{
	POBJECT_HEAD sub_menu_win;
    UINT32 param;
	sub_menu_win = menus[idx];
	if(sub_menu_win != NULL)
	{
#if 0      
  #if (SYS_PROJECT_FE == PROJECT_FE_DVBC)
		if(sub_menu_win == (POBJECT_HEAD)&win_country_net_con)
		{
			void win_contry_net_set_entry(BOOL auto_scan);
			win_contry_net_set_entry(TRUE);
		}
	     else if(sub_menu_win == (POBJECT_HEAD)&g_win_search)
		{
			extern void win_search_set_autoscan_param(void);
			win_search_set_autoscan_param();
		}
		else if(sub_menu_win == (POBJECT_HEAD)&win_lan_con)
		{
			extern void set_win_lang_as_welcome(BOOL iswelcome);
			set_win_lang_as_welcome(FALSE);
		}
         else if(sub_menu_win == (POBJECT_HEAD)&g_win_usb_filelist)
         {
             wincom_close_title();
         }
  #endif        
#endif
        param = MENU_OPEN_TYPE_MENU + idx + C_SUBMENU_ID_BASE;
        if(isdbt_installation_submenu_items == menus)
        {            
            param |= MENU_FOR_ISDBT;    
        }
#ifdef DVBC_SUPPORT
	if((POBJECT_HEAD)&win_country_net_con==sub_menu_win)
		from_auto_scan=TRUE;
#endif
		if(OSD_ObjOpen(sub_menu_win, param) != PROC_LEAVE)
 			menu_stack_push(sub_menu_win);
 	}
}

#ifdef DISK_MANAGER_SUPPORT
static BOOL check_disk_info_item_is_active()
{
	int disk_num, disk_tot_num = 0;
	int dm_ret;
	BOOL ret = TRUE;
		
	dm_ret = dm_ioctl(DM_CMD1_GET_DISK_NUM, DM_CMD_PARAM(MNT_TYPE_USB, 0, 0), &disk_num, sizeof(int));
	if (dm_ret == 0 && disk_num > 0)
		disk_tot_num += disk_num;

	dm_ret = dm_ioctl(DM_CMD1_GET_DISK_NUM, DM_CMD_PARAM(MNT_TYPE_SD, 0, 0), &disk_num, sizeof(int));
	if (dm_ret == 0 && disk_num > 0)
		disk_tot_num += disk_num;

	dm_ret = dm_ioctl(DM_CMD1_GET_DISK_NUM, DM_CMD_PARAM(MNT_TYPE_IDE, 0, 0), &disk_num, sizeof(int));
	if (dm_ret == 0 && disk_num > 0)
		disk_tot_num += disk_num;

	dm_ret = dm_ioctl(DM_CMD1_GET_DISK_NUM, DM_CMD_PARAM(MNT_TYPE_SATA, 0, 0), &disk_num, sizeof(int));
	if (dm_ret == 0 && disk_num > 0)
		disk_tot_num += disk_num;

	if (disk_tot_num <= 0)
	{
		ret = FALSE;
	}
	
 	return ret;
}
#endif


extern TITLE_TYPE mp_title_type;
extern UINT8 switch_title;
static PRESULT mediaplayer_con_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	unact;
	UINT8	id = OSD_GetObjID(pObj) + sub_menu_desc->list_top;
#ifdef USB_MP_SUPPORT
	struct statvfs usb_info;
#endif
	
	switch(event)
	{
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16) ;
		if(unact == VACT_ENTER)
		{
#if((defined USB_MP_SUPPORT) && (!defined DISABLE_USB)) 
#ifdef USB_SAFELY_REMOVE_SUPPORT
/*			if(id == TOOLS_USB_REMOVE_ID)
            {
                if (api_usb_device_safely_remove())
                {
#ifndef DISK_MANAGER_SUPPORT
                    g_show_usb_safely_removed = 1;
#endif
                }
                else
                {
    				UINT8 back_saved;
	    			win_compopup_init(WIN_POPUP_TYPE_OK);
				    win_compopup_set_msg(NULL, NULL, RS_USB_SAFELY_REMOVE_FAILED);
				    win_compopup_open_ext(&back_saved);
#ifndef DISK_MANAGER_SUPPORT
                    if (!storage_usb_menu_item_ready())
                    {
            			ap_send_msg(CTRL_MSG_SUBTYPE_CMD_ENTER_ROOT,(UINT32)(&g_win_mainmenu),TRUE);
                    }
#endif
                }

    			ret = PROC_LOOP;            
                break;
            }*/
#endif
			if(id == MEDIAPLAYER_RECORD_ID)
			{
				if(get_stroage_device_number(STORAGE_TYPE_ALL) > 0 )
				{
						if(OSD_ObjOpen((POBJECT_HEAD)&g_win_record,(UINT32)(~0)) != PROC_LEAVE)
						{
							menu_stack_push((POBJECT_HEAD)&g_win_record);
						}
				}
				return PROC_LOOP;
			}
			if((id == MEDIAPLAYER_VIDEO_ID)
				||(id == MEDIAPLAYER_MUSIC_ID)
				||(id == MEDIAPLAYER_IMAGE_ID))
			{
				if(get_stroage_device_number(STORAGE_TYPE_ALL) > 0 )
				{
#if(((!defined SUPPORT_CAS9)&&(!defined FTA_ONLY)&&(!defined SUPPORT_VMX_STD)&&(!defined SUPPORT_VMX))|| (defined MEDIAPLAYER_SUPPORT))				
					switch_title = TRUE;
					mp_title_type = TITLE_VIDEO;
					if(id == MEDIAPLAYER_MUSIC_ID)
						mp_title_type = TITLE_MUSIC;
					if(id == MEDIAPLAYER_IMAGE_ID)
						mp_title_type = TITLE_IMAGE;

                #ifdef DLNA_DMP_SUPPORT			
                    mp_set_dlna_play(FALSE);
                #endif
					enter_sub_menu(mediaplayer_sub_menus,id - 1);
					
#endif						
				}
				return PROC_LOOP;
			}
#endif

/*
#ifdef SUPPORT_IRAN_CALENDAR
			if(id==CALENDAR_ID)
			{
				calender_init();
			}
#endif
*/
#ifdef DLNA_DMP_SUPPORT
		    if(id == MEDIAPLAYER_DMP_ID)
		    {
        		switch_title = TRUE;
        		mp_title_type = TITLE_VIDEO;
                mp_set_dlna_play(TRUE);
        		enter_sub_menu(mediaplayer_sub_menus,id - 1);
        		ret = PROC_LOOP;
		    }
#endif            
#ifdef DLNA_DMR_SUPPORT
		    if(id == MEDIAPLAYER_DMR_ID)
		    {
        		enter_sub_menu(mediaplayer_sub_menus,id - 1);
        		ret = PROC_LOOP;
		    }
#endif            
#ifdef DLNA_DMS_SUPPORT
		    if(id == MEDIAPLAYER_DMS_ID)
		    {
        		enter_sub_menu(mediaplayer_sub_menus,id - 1);
        		ret = PROC_LOOP;
		    }
#endif            

		}

	}

	return ret;
}

static UINT8 mediaplayer_check_item_active(UINT32 id)
{
	UINT8 action;

	action = C_ATTR_ACTIVE;
	
	switch(id)
	{
#if((defined USB_MP_SUPPORT) && (!defined DISABLE_USB)) 
 	case MEDIAPLAYER_RECORD_ID:
 		if(!check_storage_item_is_active())
 			action = C_ATTR_INACTIVE;
		#if (VMX_PVR_CHANNEL_ID_NUM < 3)
		else if(pvr_info.rec_num >= 2)
			action = C_ATTR_INACTIVE;
		#endif
		break;
		
 	case MEDIAPLAYER_VIDEO_ID:
 		if(!check_storage_item_is_active())
 			action = C_ATTR_INACTIVE;
		#ifdef VMX_PVR_SUPPORT
		else if(api_pvr_is_record_active())
			action = C_ATTR_INACTIVE;
		#endif
		break;
		
 	case MEDIAPLAYER_MUSIC_ID:
 		if(!check_storage_item_is_active())
 			action = C_ATTR_INACTIVE;
		#ifdef VMX_PVR_SUPPORT
		else if(api_pvr_is_record_active())
			action = C_ATTR_INACTIVE;
		#endif
		break;
		
 	case MEDIAPLAYER_IMAGE_ID:
 		if(!check_storage_item_is_active())
 			action = C_ATTR_INACTIVE;
		#ifdef VMX_PVR_SUPPORT
		else if(api_pvr_is_record_active())
			action = C_ATTR_INACTIVE;
		#endif
		break;
#endif		
#ifdef DLNA_DMP_SUPPORT
    case MEDIAPLAYER_DMP_ID:
        if(api_pvr_is_record_active())
        {
            action = C_ATTR_INACTIVE;
        }
        break;
#endif
#ifdef DLNA_DMR_SUPPORT
    case MEDIAPLAYER_DMR_ID:
        if(api_pvr_is_record_active())
        {
            action = C_ATTR_INACTIVE;
        }
        break;
#endif
	}

	return action;
}
#ifdef _INVW_JUICE   
extern BOOL back_from_scan;
#endif
static PRESULT editchannel_con_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	unact;
	UINT8	id = OSD_GetObjID(pObj) + sub_menu_desc->list_top;
	UINT8 	back_saved;
	INT16 	i,n,parent_id;
	S_NODE  s_node;
	TIMER_SET_CONTENT* timer;
    SYSTEM_DATA* sys_data;
    
	switch(event)
	{
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16) ;
		if(unact == VACT_ENTER)
		{
			if(unact == VACT_ENTER)
			{
				if(id == CHLIST_DELETE_ALL_CHAN_ID)
				{
					//if(win_pwd_open(NULL,0))
					{
						win_compopup_init(WIN_POPUP_TYPE_OKNO);
						win_compopup_set_msg(NULL,NULL,RS_POPUP_WARNING_DELETE_ALL_CHANNEL);
						win_compopup_set_default_choice(WIN_POP_CHOICE_NO);
						ret = win_compopup_open_ext(&back_saved);
						if(ret==WIN_POP_CHOICE_YES)
					 	{
#ifdef NEW_DEMO_FRAME
							si_monitor_off(0xFFFFFFFF);
#endif
							n = get_sat_num(VIEW_ALL);
							
							recreate_prog_view(PROG_ALL_MODE,0);
							for(i=0;i<n;i++)
							{
								get_sat_at(i, VIEW_ALL,&s_node);
								del_child_prog(TYPE_SAT_NODE, s_node.sat_id);
							}
							
							update_data();
#ifdef _INVW_JUICE   
							osal_delay_ms(500);
							INVIEW_UpdateDatabase();  //v0.1.4
							back_from_scan = TRUE;
#endif
							sys_data_check_channel_groups();	
                            /*turn off all timer*/
                            sys_data = sys_data_get();
                            for(i=0;i<MAX_TIMER_NUM;i++)
                            {
        	                    timer = &sys_data->timer_set.TimerContent[i];
			                    timer->timer_mode = TIMER_MODE_OFF;                                    
                            }
                            
							ret = PROC_LEAVE;

							key_pan_display("noCH", 4);
					 	}
					}
				}
				else
				{
					enter_sub_menu(editchannel_sub_menus,id - 1);
					ret = PROC_LOOP;
				}
			}
		}
	}

	return ret;
}

static UINT8 editchannel_check_item_active(UINT32 id)
{
	UINT8 action;
	UINT8 tv_grps,radio_grps;

	action = C_ATTR_ACTIVE;
	tv_grps = sys_data_get_sate_group_num(TV_CHAN);
	radio_grps = sys_data_get_sate_group_num(RADIO_CHAN);
	
	switch(id)
	{
	case CHLIST_TV_LIST_ID:
		if(tv_grps == 0)
			action = C_ATTR_INACTIVE;
		break;
	case CHLIST_RADIO_LIST_ID:	
		if(radio_grps == 0)
			action = C_ATTR_INACTIVE;			
		break;
	case CHLIST_DELETE_ALL_CHAN_ID:
		if(tv_grps +  radio_grps == 0)
			action = C_ATTR_INACTIVE;			
		break;
	}

#ifdef DVR_PVR_SUPPORT
	if(api_pvr_is_record_active())
		action = C_ATTR_INACTIVE;
#endif
	

	return action;
}


extern UINT8 antset_cur_tuner;
UINT8   single_multi_srch_flag = 0;	/* 0 - single srch, 1 - multi srch*/
P_NODE playing_pnode;
static PRESULT installation_con_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	unact;
	UINT8	id = OSD_GetObjID(pObj) + sub_menu_desc->list_top;
	SYSTEM_DATA* sys_data;
    UINT8 i;
    char msg_str[40];
	POBJECT_HEAD  submenu = NULL;
    UINT32        str_id;
    POBJECT_HEAD  menu;
    POBJECT_HEAD * install_head = NULL;
    UINT32        install_type;

#if 0//defined(_S3281_) && defined(DVBC_SUPPORT)
    extern CONTAINER g_win_autoscan_qamb;
    SYSTEM_DATA* sys_data_t;
    sys_data_t = sys_data_get();
    if(sys_data_t->dvbc_mode ==0)
        dvbc_installation_submenu_items[1] = (POBJECT_HEAD)&win_country_net_con;
    else
        dvbc_installation_submenu_items[1] = (POBJECT_HEAD)&g_win_autoscan_qamb;
#endif
    
    if(sub_menu_desc != ((sub_menu_t*)&sub_menu_installation))
    {
        if(sub_menu_desc == &sub_menu_installation_dvbs)
        {
            submenu = dvbs_installation_submenu_items[id - 1];
            install_head = (POBJECT_HEAD *)&dvbs_installation_submenu_items[0];
        }
        else if(sub_menu_desc == &sub_menu_installation_dvbt)
        {
            submenu = dvbt_installation_submenu_items[id - 1];
            install_head = (POBJECT_HEAD *)&dvbt_installation_submenu_items[0];
        }
        else if(sub_menu_desc == &sub_menu_installation_dvbc)
        {
            submenu = dvbc_installation_submenu_items[id - 1];
            install_head = (POBJECT_HEAD *)&dvbc_installation_submenu_items[0];
            
        }
        else if(sub_menu_desc == &sub_menu_installation_isdbt)
        {
            submenu = isdbt_installation_submenu_items[id - 1];
            install_head = (POBJECT_HEAD *)&isdbt_installation_submenu_items[0];
        }     
    }
    
	switch(event)
	{
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16) ;
		if(unact == VACT_ENTER)
		{ 
            
            if(submenu != NULL)
            {
    			sys_data_get_curprog_info(&playing_pnode);
                if(submenu == (POBJECT_HEAD)&g_win_sat_srchset)
                {
                    if(sub_menu_desc->items[id-1].item_name == RS_INSTALLATION_SINGLE_SEARCH)
                        single_multi_srch_flag = 0;	/* Single search */
                    else
                        single_multi_srch_flag = 1;	/* Multi search */
                }

                if(submenu == (POBJECT_HEAD)&g_win_antenna_set_fixed) /* Antenna setting */
                {                
                    i = 0;
                    while(i < get_tuner_cnt())
                    {
                        cur_tuner_idx = antset_cur_tuner = i;
                        if(get_tuner_sat_cnt(antset_cur_tuner) == 0)
                        {
                            UINT8 back_saved;
                            win_compopup_init(WIN_POPUP_TYPE_OK);
                            sprintf(msg_str, "Tuner %d has no satellite select!", i+1);
                            win_compopup_set_msg(msg_str,NULL, 0);
                            win_compopup_open_ext(&back_saved);                           
                        }
                        else
                        {
                            break;
                        }
                        i++;
                    }
                    
                    sys_data = sys_data_get();
                    if(sys_data->tuner_lnb_type[antset_cur_tuner] == LNB_MOTOR)
                        submenu = (POBJECT_HEAD)&g_win_antenna_set_motor;
                    //else
                    //    submenu = installation_sub_menus[id - 1];
                #ifdef DVBS_SUPPORT
                    set_movedish_flag(FALSE);/*False to move dish,True not to move*/
                #endif
                    if(OSD_ObjOpen(submenu,MENU_OPEN_TYPE_MENU + id) != PROC_LEAVE)
                        menu_stack_push(submenu);

                }
    			else
                   enter_sub_menu(install_head,id - 1);
    				//enter_sub_menu(installation_sub_menus,id - 1);
            } 
            else
            {
                str_id = installation_items[id - 1].item_name;
                menu = (POBJECT_HEAD)&g_win_submenu;
                switch(str_id)
                {
                    case RS_INSTALLATION_DVBS:
                        submenu_set_items(&sub_menu_installation_dvbs);
                    break;
                    case RS_INSTALLATION_DVBT:
                        submenu_set_items(&sub_menu_installation_dvbt);
                        break;
                    case RS_INSTALLATION_DVBC:
                        submenu_set_items(&sub_menu_installation_dvbc);
                        break;
                    case RS_INSTALLATION_ISDBT:
                        submenu_set_items(&sub_menu_installation_isdbt);                        
                        break;
                    default:
                        break;
                }
                wincom_open_title(pObj,sub_menu_desc->title_id, 0);
                submenu_show();

                OSD_TrackObject(menu, C_DRAW_SIGN_EVN_FLG | C_UPDATE_FOCUS);
    			menu_stack_push(menu);                
            }
			ret = PROC_LOOP;
		}
        break;
    default:
        break;
	}
	return ret;
}


static UINT8  installation_check_item_active(UINT32 id)
{
	UINT8 action;
	action = C_ATTR_ACTIVE;

    POBJECT_HEAD submenu = NULL;// installation_sub_menus[id-1];

    if(sub_menu_desc == (sub_menu_t*)&sub_menu_installation)
         submenu =  installation_sub_menus[id-1];
    else if(sub_menu_desc == (sub_menu_t*)&sub_menu_installation_dvbs)
         submenu =  dvbs_installation_submenu_items[id-1];
    else if(sub_menu_desc == (sub_menu_t*)&sub_menu_installation_dvbt)
         submenu =  dvbt_installation_submenu_items[id-1];
    else if(sub_menu_desc == (sub_menu_t*)&sub_menu_installation_isdbt)
         submenu =  isdbt_installation_submenu_items[id-1];
    else if(sub_menu_desc == (sub_menu_t*)&sub_menu_installation_dvbc)
         submenu =  dvbc_installation_submenu_items[id-1];
    
    
    if(submenu == (POBJECT_HEAD)&g_win_antenna_set_fixed ||
       submenu == (POBJECT_HEAD)&g_win_sat_srchset ||   
       submenu == (POBJECT_HEAD)&g_win_tplist)
    {
		if(get_tuner_sat_cnt(TUNER_EITHER) == 0)
			action = C_ATTR_INACTIVE;	        
    }
    	
#ifdef DVR_PVR_SUPPORT
	if(api_pvr_is_record_active())
	{ 
		action = C_ATTR_INACTIVE;
	}
#endif
	return action;
}

#if defined( SUPPORT_CAS9) ||defined (SUPPORT_CAS7) 
extern UINT8 Correct_card;
extern UINT16 card_msg_id;

static PRESULT ca_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
    PRESULT ret = PROC_PASS;
	UINT8	unact;
    UINT8 back_saved;
	UINT8	id = OSD_GetObjID(pObj) + sub_menu_desc->list_top;
    struct smc_device *smc_dev;
	smc_dev = (struct smc_device *)dev_get_by_id(HLD_DEV_TYPE_SMC, 0);
	
	switch(event)
	{
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16) ;
		if(unact == VACT_ENTER)
		{
            //if((smc_card_exist(smc_dev) == SUCCESS))
			#ifndef CAS9_V6  //20130709#4_ca_menu
            if(ca_is_card_inited() == TRUE)
			#endif
			{
				enter_sub_menu(windows_ca_list,id - 1);
			}
			#ifndef CAS9_V6 //20130709#4_ca_menu
			else
			{
				win_compopup_init(WIN_POPUP_TYPE_SMSG);
				//win_compopup_set_msg(NULL, NULL, RS_CONAX_NO_CARD);
				win_compopup_set_msg(NULL, NULL, card_msg_id);
				#ifndef SD_UI
                win_compopup_set_frame(290, 130, 480, 100);
				#else
				win_compopup_set_frame(140, 100, 320, 60);
				#endif
				win_compopup_open_ext(&back_saved);
				osal_task_sleep(1000);
				win_compopup_smsg_restoreback();
			}
			#endif
		}
        ret = PROC_LOOP;
		break;
	}

	return ret;
}

static UINT8  ca_check_item_active(UINT32 id)
{
    UINT8 action;
	action = C_ATTR_ACTIVE;
	
	switch(id)
	{
	case WIN_SUBSCRIPTION_ID:
	case WIN_EVENT_ID:
	case WIN_PURSE_ID:
	case WIN_CAPIN_ID:
	case WIN_MATURITY_ID:
	case WIN_CAABOUT_ID:
    case WIN_MAILLIST_ID:
		#ifdef CAS9_V6 //20130709#4_ca_menu
			if((ca_is_card_inited() != TRUE) && (id != WIN_CAABOUT_ID) && (id != WIN_MAILLIST_ID)) /* ca about and mail list menu don't need smartcard */
		{
			action = C_ATTR_INACTIVE;
		}
		#endif
        break;
	}

    #ifdef DVR_PVR_SUPPORT
    	if(api_pvr_is_record_active())
    	{ 
    		action = C_ATTR_INACTIVE;
    	}
    #endif

	return action;
}
#endif

static PRESULT system_con_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	unact;
	UINT8	id = OSD_GetObjID(pObj) + sub_menu_desc->list_top;
	
	switch(event)
	{
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16) ;
		if(unact == VACT_ENTER)
		{
		#ifdef SUPPORT_CAS_A 
			if(system_sub_menus[id - 1]==(POBJECT_HEAD)&g_win_tv_access)
			{
				if(!api_abel_cas_check_card_inited())
				{
					UINT8 save;
					win_compopup_init(WIN_POPUP_TYPE_SMSG);
					win_compopup_set_msg("No smart card or invalid card", NULL, NULL);
					win_compopup_open_ext(&save);
					osal_task_sleep(1500);
					win_compopup_smsg_restoreback();						
					return ret;
				}
			}
		#endif	
		#ifndef DISK_MANAGER_SUPPORT
 			if(id == RECORD_HDDFORMAT_ID)
			{
				hddfmt_win_set_type(TRUE);
			}
 			else if((id == RECORD_HDDINFO_ID)
				||(id == RECORD_PVRMANAGE_ID)
				||(id == RECORD_PVR_SETTING))
			{
 				hddfmt_win_set_type(FALSE);
 			}
		#endif
			enter_sub_menu(system_sub_menus,id - 1);
			ret = PROC_LOOP;
		}

	}

	return ret;
}
//Gavim@menu
static PRESULT  root_time_con_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	unact;
	UINT8	id = OSD_GetObjID(pObj) + sub_menu_desc->list_top;
	libc_printf("====root_time_con_item_callback = \n"  );
	/*
	switch(event)
	{
	//case EVN_PRE_OPEN:
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16) ;
		if(unact == VACT_ENTER)
		{
			//enter_sub_menu(system_sub_menus,id - 1);
			enter_sub_menu(root_time_sub_menus,id - 1);
			ret = PROC_LOOP;
		}

	}
*/
  //  ret = PROC_LOOP;
     ret = PROC_PASS;
	return ret;
}
//-------------------------------------------------------

static UINT8  system_check_item_active(UINT32 id)
{
	UINT8 action;

	action = C_ATTR_ACTIVE;
	
	switch(id)
	{
//Gavim@menu
//	case SYSTEM_LANG_ID:
	case SYSTEM_TV_ID:
#if (AOV_OSD_DISPLAY_SETTING_ENABLE == SYS_FUNC_ON)
#ifdef _INVW_JUICE
#ifdef DISPLAY_SETTING_SUPPORT
	case SYSTEM_DISPLAY_ID:
#endif
#endif
#endif
//Gavim@menu
//	case SYSTEM_TIME_ID:
#ifdef EWS_INDONESIA_DEMO
    case EWS_INDONESIA_ID:
#endif
	case SYSTEM_PARENT_ID:
	case SYSTEM_OSDSET_ID:
#ifdef MULTIVIEW_SUPPORT
	case SYSTEM_MULTIVIEW_ID:
#endif	

#ifdef _INVW_JUICE 
#else
#ifdef FAV_GROP_RENAME		
	case SYSTEM_FAVNAME_ID:
#endif		
#endif
#ifndef NEW_DEMO_FRAME
	case SYSTEM_STO_SETTING_ID:
		break;		
#endif
#ifdef _INVW_JUICE
#ifdef AUDIO_DESCRIPTION_SUPPORT
	case SYSTEM_AUDIO_DESCRIPTION_ID:
#endif
#endif
	case SYSTEM_MISC_ID:
		break;
#ifdef _INVW_JUICE//chunpintime 
#else                 
	case SYSTEM_TIMER_ID:	
		if(sys_data_get_group_num() == 0)
			action = C_ATTR_INACTIVE;
	
#ifdef DVR_PVR_SUPPORT
		if(api_pvr_is_record_active())
			action = C_ATTR_INACTIVE;
#endif
		break;
#endif	

#ifndef DISABLE_PVR_TMS
	case RECORD_HDDINFO_ID:
#ifdef DISK_MANAGER_SUPPORT
		if (!check_disk_info_item_is_active())
			action = C_ATTR_INACTIVE;
#endif
		break;
	case RECORD_PVR_SETTING:	
 		if ((!pvr_info.hdd_valid) || api_pvr_is_record_active())
			action = C_ATTR_INACTIVE;	
		break;

#ifdef _INVW_JUICE
#ifndef DISK_MANAGER_SUPPORT
	case RECORD_PVRMANAGE_ID:
		action = C_ATTR_INACTIVE;	
		break;

	case RECORD_HDDFORMAT_ID:
		action = C_ATTR_INACTIVE;	
		break;
#endif
#endif

#endif

    default:
        break;
	}
	return action;
}

#ifdef USB_MP_SUPPORT
#ifdef USB_SAFELY_REMOVE_SUPPORT
BOOL api_usb_device_safely_remove(void);
#ifndef DISK_MANAGER_SUPPORT
UINT8 g_show_usb_safely_removed;
#endif
#endif

#endif


static PRESULT tools_con_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	unact;
	UINT8	id = OSD_GetObjID(pObj) + sub_menu_desc->list_top;
#ifdef USB_MP_SUPPORT
	struct statvfs usb_info;
#endif
	
	switch(event)
	{
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16) ;
		if(unact == VACT_ENTER)
		{
#if((defined USB_MP_SUPPORT) && (!defined DISABLE_USB)) 
#ifdef USB_SAFELY_REMOVE_SUPPORT
			if(id == TOOLS_USB_REMOVE_ID)
            {
                if (api_usb_device_safely_remove())
                {
#ifndef DISK_MANAGER_SUPPORT
                    g_show_usb_safely_removed = 1;
#endif
                }
                else
                {
    				UINT8 back_saved;
	    			win_compopup_init(WIN_POPUP_TYPE_OK);
				    win_compopup_set_msg(NULL, NULL, RS_USB_SAFELY_REMOVE_FAILED);
				    win_compopup_open_ext(&back_saved);
#ifndef DISK_MANAGER_SUPPORT
                    if (!storage_usb_menu_item_ready())
                    {
            			ap_send_msg(CTRL_MSG_SUBTYPE_CMD_ENTER_ROOT,(UINT32)(&g_win_mainmenu),TRUE);
                    }
#endif
                }

    			ret = PROC_LOOP;            
                break;
            }
#endif
/*			if(id == TOOLS_USB_ID)
			{
				if(get_stroage_device_number(STORAGE_TYPE_ALL) > 0 )
				{
#if (!(defined( SUPPORT_CAS9) ) || (defined MEDIAPLAYER_SUPPORT))				
					if(mp_title_type != TITLE_RECORD)
					{
						enter_sub_menu(tools_sub_menus,id - 1);
						//ap_send_msg(CTRL_MSG_SUBTYPE_STATUS_USBMOUNT,0,0);
					}
					else
#endif						
					{
						if(OSD_ObjOpen((POBJECT_HEAD)&g_win_record,(UINT32)(~0)) != PROC_LEAVE)
						{
							menu_stack_push((POBJECT_HEAD)&g_win_record);
						}
					}
				}
				return PROC_LOOP;
			}*/
#endif

#ifdef SUPPORT_IRAN_CALENDAR
			if(id==CALENDAR_ID)
			{
				calender_init();
			}
#endif
#if (AOV_OSD_GAME_ENABLE == SYS_FUNC_ON)
			if(id==GAMES_SNAKE_ID)
			{
				game_othello_init();
			}
			else if(id==GAMES_SUDOKU_ID)
			{
				game_sudoku_init();
			}
#endif			
			enter_sub_menu(tools_sub_menus,id - 1);
			ret = PROC_LOOP;
		}

	}

	return ret;
}

#ifndef DISK_MANAGER_SUPPORT
BOOL check_storage_item_is_active()
{
    struct statvfs usb_info;
	BOOL ret = TRUE;
	if(!storage_menu_item_ready())
        ret = FALSE;
    if (fs_statvfs("/mnt", &usb_info) <  0)
        ret = FALSE;
    else if(usb_info.f_blocks == 0)//usb device do not exist or mount failure
		ret = FALSE;
#ifdef DVR_PVR_SUPPORT
	else if(api_pvr_is_record_active())
	{
	    ret = FALSE;
	}
#endif
	return ret;
}

BOOL check_usb_item_is_active()
{
    struct statvfs usb_info;
 	BOOL ret = TRUE;
 	if(!storage_usb_menu_item_ready())
         ret = FALSE;
    if (fs_statvfs(MP3_ROOT_DIR, &usb_info) <  0)
        ret = FALSE;
    else if(usb_info.f_blocks == 0)//usb device do not exist or mount failure
		ret = FALSE;
#ifdef DVR_PVR_SUPPORT
 	else if(api_pvr_is_record_active())
 	{
	    ret = FALSE;
 	}
#endif
 	return ret;
}
#else /* DISK_MANAGER_SUPPORT */

BOOL check_usb_item_is_active()
{
	int vol_num, tot_vol_num = 0;
	int dm_ret;
	BOOL ret = TRUE;
		
	dm_ret = dm_ioctl(DM_CMD1_GET_VOL_NUM, DM_CMD_PARAM(MNT_TYPE_USB, 0, 0), &vol_num, sizeof(int));
	if (dm_ret == 0 && vol_num > 0)
		tot_vol_num += vol_num;

	dm_ret = dm_ioctl(DM_CMD1_GET_VOL_NUM, DM_CMD_PARAM(MNT_TYPE_SD, 0, 0), &vol_num, sizeof(int));
	if (dm_ret == 0 && vol_num > 0)
		tot_vol_num += vol_num;

	dm_ret = dm_ioctl(DM_CMD1_GET_VOL_NUM, DM_CMD_PARAM(MNT_TYPE_IDE, 0, 0), &vol_num, sizeof(int));
	if (dm_ret == 0 && vol_num > 0)
		tot_vol_num += vol_num;

	dm_ret = dm_ioctl(DM_CMD1_GET_VOL_NUM, DM_CMD_PARAM(MNT_TYPE_SATA, 0, 0), &vol_num, sizeof(int));
	if (dm_ret == 0 && vol_num > 0)
		tot_vol_num += vol_num;

	if (tot_vol_num <= 0)
	{
		ret = FALSE;
	}
	
#if defined(DVR_PVR_SUPPORT)&&!defined(VMX_PVR_SUPPORT)
	if (api_pvr_is_record_active())
	{
		ret = FALSE;
	}
#endif

 	return ret;
}

BOOL check_storage_item_is_active()
{
	BOOL ret = check_usb_item_is_active();
//#if(((defined SUPPORT_CAS9)||(defined SUPPORT_CAS7)) && (!defined MEDIAPLAYER_SUPPORT))
#if((defined SUPPORT_CAS9 || defined FTA_ONLY || defined SUPPORT_VMX_STD|| defined SUPPORT_VMX) && (!defined MEDIAPLAYER_SUPPORT))
	if(!pvr_info.hdd_valid)
#else
	if (!ap_mp_is_ready())
#endif		
	{
		ret = FALSE;
	}
	return ret;
}

#endif /* DISK_MANAGER_SUPPORT */
		
BOOL check_rs232_item_is_active()
{//for 3281 erom
	BOOL ret = FALSE;
#if (defined(_S3281_)&&defined(_EROM_UPG_HOST_ENABLE_))	
	unsigned long erom_chunk_id = EROM_CLIENT_ID;
	CHUNK_HEADER chunk_hdr;	
	if(sto_get_chunk_header(erom_chunk_id,&chunk_hdr)!=0)
	{
		ret = TRUE;
	}	
#endif
	return ret;
}

static UINT8  tools_check_item_active(UINT32 id)
{
	UINT8 action;
	action = C_ATTR_ACTIVE;
    
#ifdef USB_MP_SUPPORT
    struct statvfs usb_info;
#endif

#ifdef HILINK_SUPPORT
    unsigned int hilink_falg = 0;
#endif
	switch(id)
	{
	case TOOLS_INFO_ID:
		break;
/*	case TOOLS_SATCODX_ID:
		
		if(get_tuner_sat_cnt(TUNER_EITHER) == 0)
			action = C_ATTR_INACTIVE;
		break;
*/	
	case TOOLS_FACTORYSET_ID:
	
#if (AOV_OSD_UPGRADE_USE_RS232_ENABLE == SYS_FUNC_ON)
//#if((defined _S3281_)||(!(defined(SUPPORT_CAS7) ||defined(SUPPORT_CAS9))))
#if((defined(_S3281_)&&defined(_EROM_UPG_HOST_ENABLE_))||(!(defined(SUPPORT_CAS9)||defined(FTA_ONLY)||defined(CI_PLUS_SUPPORT)||defined(SUPPORT_VMX)||defined(SUPPORT_VMX_STD) )))
	case TOOLS_RS232UPG_ID:

#endif		
#endif

	case TOOLS_OTAUPG_ID:

#ifdef NETWORK_SUPPORT
	case TOOLS_NET_UPG_ID:
#endif
#ifdef DVR_PVR_SUPPORT
		if(api_pvr_is_record_active())
		{ 
			action = C_ATTR_INACTIVE;
		}
#endif
		if(id == TOOLS_OTAUPG_ID)
		{
    //#if (SYS_PROJECT_FE == PROJECT_FE_DVBS || SYS_PROJECT_FE == PROJECT_FE_DVBS2)
	//		if(get_tuner_sat_cnt(TUNER_EITHER) == 0)
	//			action = C_ATTR_INACTIVE;
    //#endif            
		}	
#if (AOV_OSD_UPGRADE_USE_RS232_ENABLE == SYS_FUNC_ON)
//#if((defined _S3281_)||(!(defined(SUPPORT_CAS7) ||defined(SUPPORT_CAS9))))
#if((defined(_S3281_)&&defined(_EROM_UPG_HOST_ENABLE_))||(!(defined(SUPPORT_CAS9)||defined(FTA_ONLY)||defined(CI_PLUS_SUPPORT)||defined(SUPPORT_VMX)||defined(SUPPORT_VMX_STD))))
		if(id == TOOLS_RS232UPG_ID)
		{
			//3281 erom upg, check the eromclient chunk valid
			if(ALI_S3281==sys_ic_get_chip_id()) 
			{
				if(!check_rs232_item_is_active())
					action = C_ATTR_INACTIVE;
			}
		}
#endif
#endif
		break;
#if((defined USB_MP_SUPPORT) && (!defined DISABLE_USB)) 
// 	case TOOLS_USB_ID:
// 		if(!check_storage_item_is_active())
//			action = C_ATTR_INACTIVE;
//		break;
//#if  !( defined(SUPPORT_CAS7) ||defined(SUPPORT_CAS9))
#if  !( defined(SUPPORT_CAS9)|| defined(DISABLE_USB_UPG))	
	case TOOLS_USBUPG_ID:
#endif		
#ifdef USB_SAFELY_REMOVE_SUPPORT
	case TOOLS_USB_REMOVE_ID:
#endif
		if(!check_usb_item_is_active())
			action = C_ATTR_INACTIVE;
		break;
#endif

#ifdef NETWORK_SUPPORT
#ifdef WIFI_SUPPORT
#ifdef _INVW_JUICE//chunpintime  
#else 
//#ifdef WIFI_DIRECT_SUPPORT
//	case TOOLS_NET_WIFI_DIRECT_SETTING_ID:
//#endif                
#ifdef ALICAST_SUPPORT
	case TOOLS_ALI_CAST_ID:	
#endif
        {
		    if(!api_wifi_get_device_plugged_status())
			    action = C_ATTR_INACTIVE;			
        }
		break;
#endif
#endif
#endif

#ifdef _ALI_PLAY_VERSION_
	case TOOLS_ALIPLAY_ID:
		if (0 == aliplay_service_is_running()) {
		        action = C_ATTR_INACTIVE;
	        }
		break;
#endif
	
	default:
		break;
	}

	return action;
}

static PRESULT games_con_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	unact;
	UINT8	id = OSD_GetObjID(pObj) + sub_menu_desc->list_top;
	
	switch(event)
	{
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16) ;
		if(unact == VACT_ENTER)
		{
#if (AOV_OSD_GAME_ENABLE == SYS_FUNC_ON)
			if(id==GAMES_SNAKE_ID)
			{
				game_othello_init();
			}
			else if(id==GAMES_SUDOKU_ID)
			{
				game_sudoku_init();
			}
#endif			
			enter_sub_menu(games_sub_menus,id - 1);
			ret = PROC_LOOP;
		}

	}

	return ret;
}

#ifndef DISABLE_PVR_TMS

#ifdef DVR_PVR_SUPPORT
/*************record***************/

static PRESULT record_con_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	unact;
	UINT8	id = OSD_GetObjID(pObj) + sub_menu_desc->list_top;
	
	switch(event)
	{
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16) ;
		if(unact == VACT_ENTER)
		{
#ifndef DISK_MANAGER_SUPPORT
 			if(id == RECORD_HDDFORMAT_ID)
			{
				hddfmt_win_set_type(TRUE);
			}
 			else
			{
 				hddfmt_win_set_type(FALSE);
 			}
#endif
			enter_sub_menu(record_sub_menus,id - 1);
			ret = PROC_LOOP;
		}

	}

	return ret;
}


static UINT8  record_check_item_active(UINT32 id)
{
	UINT8 action;

	action = C_ATTR_ACTIVE;
	
	switch(id)
	{
	case RECORD_HDDINFO_ID:
#ifdef DISK_MANAGER_SUPPORT
		if (!check_disk_info_item_is_active())
			action = C_ATTR_INACTIVE;
#endif
		break;
	case RECORD_PVR_SETTING:	
 		if ((!pvr_info.hdd_valid) || api_pvr_is_record_active())
			action = C_ATTR_INACTIVE;	
		break;

	}

	return action;
}
#endif

#endif

void win_submenu_set_focus(UINT8 mm_focus, UINT8 sub_foucs)
{
	mainmenu_sub_menus[mm_focus]->list_sel = sub_foucs;

	if(sub_foucs > C_SUBMENU_PAGE)
	{
		 mainmenu_sub_menus[mm_focus]->list_top = sub_foucs - C_SUBMENU_PAGE-1;
	}
}


BOOL installation_menu_is_sub_menu_state(void)
{
    BOOL ret = FALSE;
    if( sub_menu_desc == &sub_menu_installation_dvbs
       || sub_menu_desc == &sub_menu_installation_dvbt
       || sub_menu_desc == &sub_menu_installation_dvbc
       || sub_menu_desc == &sub_menu_installation_isdbt)
    {
        ret = TRUE;        
    }
    return ret;
}

void installation_menu_set_parent_menu(void)
{
    submenu_set_items(&sub_menu_installation);
}

#ifdef SAT2IP_SUPPORT


BOOL installation_dvbs_menu_is_top(void)
{
    INT32           i;
    BOOL            ret = FALSE;
    POBJECT_HEAD    p_menu = NULL;
    p_menu = menu_stack_get_top();
    for(i = 0; i < sizeof(dvbs_installation_submenu_items)/sizeof(dvbs_installation_submenu_items[0]);i++)
    {
        if(p_menu == dvbs_installation_submenu_items[i])
        {
            ret = TRUE;
            break;
        }
    }
    return ret;
}
BOOL installation_dvbc_menu_is_top(void)
{
    INT32           i;
    BOOL            ret = FALSE;
    POBJECT_HEAD    p_menu = NULL;
    p_menu = menu_stack_get_top();
    for(i = 0; i < sizeof(dvbc_installation_submenu_items)/sizeof(dvbc_installation_submenu_items[0]);i++)
    {
        if(p_menu == dvbc_installation_submenu_items[i])
        {
            ret = TRUE;
            break;
        }
    }
    return ret;
}
BOOL installation_dvbt_menu_is_top(void)
{
    INT32           i;
    BOOL            ret = FALSE;
    POBJECT_HEAD    p_menu = NULL;
    p_menu = menu_stack_get_top();
    for(i = 0; i < sizeof(dvbt_installation_submenu_items)/sizeof(dvbt_installation_submenu_items[0]);i++)
    {
        if(p_menu == dvbt_installation_submenu_items[i])
        {
            ret = TRUE;
            break;
        }
    }
    return ret;
}

BOOL installation_isdbt_menu_is_top(void)
{
    INT32           i;
    BOOL            ret = FALSE;
    POBJECT_HEAD    p_menu = NULL;
    p_menu = menu_stack_get_top();
    for(i = 0; i < sizeof(isdbt_installation_submenu_items)/sizeof(isdbt_installation_submenu_items[0]);i++)
    {
        if(p_menu == isdbt_installation_submenu_items[i])
        {
            ret = TRUE;
            break;
        }
    }
    return ret;
}

BOOL installation_menu_is_top(void)
{
    BOOL ret = FALSE;

    ret = installation_dvbs_menu_is_top();
    if(ret)
    {
        goto f_exit;
    }
    ret = installation_dvbt_menu_is_top();
    if(ret)
    {
        goto f_exit;
    }
    ret = installation_dvbc_menu_is_top();
    if(ret)
    {
        goto f_exit;
    }
    ret = installation_isdbt_menu_is_top();
    if(ret)
    {
        goto f_exit;
    }        

f_exit:;
    return ret;
}

#endif

//Gavim@menu
static UINT8  root_time_check_item_active(UINT32 id)
{
	UINT8 action;

	action = C_ATTR_ACTIVE;
	
	return action;
}
